<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org"
      xmlns:sec="http://www.thymeleaf.org/thymeleaf-extras-springsecurity5">
<head>
    <meta charset="UTF-8">
    <title>首页</title>
</head>
<body>

<h2>这是首页</h2>

<div sec:authorize="!isAuthenticated()">
    <h1>尚未登录</h1><hr>
    <a th:href="@{/login}">去登录</a>
</div>

<div sec:authorize="isAuthenticated()">
    <h1>登录成功</h1><hr>
    <span sec:authentication="name"></span> <!-- 获取登录人名字 -->
    <span sec:authentication="principal.authorities"></span>  <!-- 获取角色权限信息 -->
    <form th:action="@{/logout}" method="post">
        <input type="submit" value="注销" />
    </form>
</div>

<div class="user" sec:authorize="hasRole('common')">
    <span>用户展示1</span>
    <span>用户展示2</span>
    <span>用户展示3</span>
    <span>用户展示4</span>
    <span>用户展示5</span>
</div>

<div class="manager" sec:authorize="hasRole('MANAGER')">
    <span>管理员展示1</span>
    <span>管理员展示2</span>
    <span>管理员展示3</span>
    <span>管理员展示4</span>
    <span>管理员展示5</span>
</div>

<div class="admin" sec:authorize="hasRole('ADMIN')">
    <span>超级管理员展示1</span>
    <span>超级管理员展示2</span>
    <span>超级管理员展示3</span>
    <span>超级管理员展示4</span>
    <span>超级管理员展示5</span>
</div>

</body>
</html>